/**
 * 
 */
package com.globalresources.commons;
import com.ascertia.adss.client.api.*;
import com.ascertia.adss.client.api.signing.*;
import java.io.*;
import java.net.*;
/**
 * @author Administrator
 *
 */
public class SignUtil {
	
	/*签名的profile序号
	 * 返回
	 * */	
	public static String getSignProfile(int pageNumber){
		String profileNumber;
		switch(pageNumber){		
		case 1: profileNumber="002";
		break;
		case 2:profileNumber="010";
		break;
		case 3:profileNumber="011";
		break;
		
		default:profileNumber="002";
		}		
		return profileNumber;
		
	}

	
	
	/**
	 * 进行签名
	 * 
	 * **/
	
	public static boolean signDocument(String adssServer,String userPath, String inputFile, String profileNumber, String reason, String location){
		try{
		    EmptySignatureFieldRequest obj_emptySigFieldRequest = new EmptySignatureFieldRequest("samples_test_client", userPath+inputFile);
		    obj_emptySigFieldRequest.setProfileId("adss:signing:profile:"+profileNumber);
		    obj_emptySigFieldRequest.setSigningInfo("adss:signing:profile:001", "samples_test_signing_certificate");
		    obj_emptySigFieldRequest.overrideProfileAttribute(EmptySignatureFieldRequest.SIGNING_REASON, reason);
		    obj_emptySigFieldRequest.overrideProfileAttribute(EmptySignatureFieldRequest.SIGNING_LOCATION, location);
		    /* Writing request to disk */
		    obj_emptySigFieldRequest.writeTo("/opt/java/xml/CreateEmptySigFields-request.xml");

		    /* Sending the above constructed request to the ADSS server */
		    EmptySignatureFieldResponse obj_emptySigFieldResponse = (EmptySignatureFieldResponse) obj_emptySigFieldRequest.send(adssServer + "/adss/signing/esi");
		    /* Writing response to disk */
		    obj_emptySigFieldRequest.writeTo("/opt/java/xml/CreateEmptySigFields-response.xml");
		    /* Parsing the response */
		    if (obj_emptySigFieldResponse.isSuccessfull()) {
		      obj_emptySigFieldResponse.publishDocument(userPath+Constant.fs+"signed"+Constant.fs+inputFile);		    
		      return true;
		    }
		    else {

		      return false;
		    }
		
		}catch(Exception e){
			return false;
		}
		
		
	}
	
	
	
	public static void main(String[] args){
		
		int pageNumber=2;
		System.out.println(getSignProfile(pageNumber));
		
		
	}
	
	

}
